home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / amiga.trm < prev    next >
Encoding:
Text File  |  1996-01-23  |  14.1 KB  |  517 lines

  1. /*
  2.  * $Id: amiga.trm,v 1.12 1995/12/20 21:47:40 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - amiga.trm */
  7. /*
  8.  * Copyright (C) 1991, 1992, 1995
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *   Amiga Custom Screen
  26.  *
  27.  * AUTHORS
  28.  *   Carsten Steger
  29.  * 
  30.  *   Pat R. Empleo      Slightly modified for Aztec C v5.2a (beta); sort of
  31.  *   08/27/91           supports overscan; for large WB 2.0 virtual screens,
  32.  *                      we limit the plot size so we don't have to scroll
  33.  *                      around (not fun).
  34.  *
  35.  *   Carsten Steger     Modified to support Kickstart 2.0.
  36.  *   09/11/91           Opens a text overscan screen when used with WB 2.0.
  37.  *                      Discerns between NTSC and PAL Amigas when used with
  38.  *                      WB 1.3 and lower.
  39.  *
  40.  *   Pat R. Empleo      Defined some 2.0 stuff in order to get Aztec C to
  41.  *   09/20/91           work with Carsten's new code (see above).  When
  42.  *                      KS/WB 2.0 support gets implemented in Aztec C, this
  43.  *                      kludge will get deleted! 
  44.  *                      (Aztec C release 5.2 beta)
  45.  *
  46.  *   Carsten Steger     Converted to new terminal layout.
  47.  *   10/01/95
  48.  *
  49.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  50.  * 
  51.  */
  52.  
  53. #ifndef GOT_DRIVER_H
  54. #include "driver.h"
  55. #endif
  56.  
  57. #ifdef TERM_REGISTER
  58. register_term(amiga)
  59. #endif
  60.  
  61. #ifdef TERM_PROTO
  62.  
  63. #define AMIGA_XMAX 640
  64. #define AMIGA_YMAX 512
  65.  
  66. #define AMIGA_VCHAR 12
  67. #define AMIGA_HCHAR 8
  68. #define AMIGA_VTIC  5
  69. #define AMIGA_HTIC  5
  70.  
  71. TERM_PUBLIC void AMIGA_reset __P((void));
  72. TERM_PUBLIC void AMIGA_init __P((void));
  73. TERM_PUBLIC void AMIGA_options __P((void));
  74. TERM_PUBLIC void AMIGA_text __P((void));
  75. TERM_PUBLIC void AMIGA_graphics __P((void));
  76. TERM_PUBLIC void AMIGA_move __P((unsigned int x, unsigned int y));
  77. TERM_PUBLIC void AMIGA_vector __P((unsigned int x, unsigned int y));
  78. TERM_PUBLIC void AMIGA_linetype __P((int linetype));
  79. TERM_PUBLIC void AMIGA_put_text __P((unsigned int x, unsigned int y,
  80.                                      char *str));
  81. TERM_PUBLIC int AMIGA_justify_text __P((enum JUSTIFY mode));
  82. TERM_PUBLIC int AMIGA_set_font __P((char * font));
  83. TERM_PUBLIC void AMIGA_suspend __P((void));
  84. TERM_PUBLIC void AMIGA_resume __P((void));
  85. #define GOT_AMIGA_PROTO
  86.  
  87. #endif /* TERM_PROTO */
  88.  
  89.  
  90. #ifndef TERM_PROTO_ONLY
  91.  
  92. #ifdef TERM_BODY
  93.  
  94.  
  95. /* we have 2 collisions now with GCC includes */
  96. /* to solve them we disabel them NOW this maybe not so good*/
  97.  
  98. #ifdef AMIGA
  99.  
  100. /* defined in limits.h AND in exec/types.h     */
  101. /* we will use the exec version         */
  102. #undef LONGBITS 
  103.  
  104. /* struct timeval is defined in devices/timer.h */
  105. /* and somewhere else */
  106.  
  107. #endif
  108.  
  109. #ifdef AMIGA_AC_5
  110. #include <intuition/intuitionbase.h>
  111. #include <intuition/screens.h>
  112. #include <graphics/text.h>
  113. #include <graphics/gfxbase.h>
  114. #else
  115. /* You will have to use the Kickstart 2.0 header files for this to compile */
  116. #include <exec/types.h>
  117. #include <intuition/intuitionbase.h>
  118. #include <graphics/gfxbase.h>
  119. #ifdef LATTICE
  120. #include <proto/intuition.h>
  121. #include <proto/graphics.h>
  122. #include <proto/exec.h>
  123. #include <proto/diskfont.h>
  124. #endif
  125.  
  126. #endif
  127.  
  128. /* The origin is in the upper left hand corner, so we have to translate */
  129. /* and flip the coordinates: */
  130. #define AMIGA_VTF(y) (AMIGA_ymax-1-(y))
  131.  
  132.  
  133. struct IntuitionBase *IntuitionBase;
  134. struct GfxBase *GfxBase;
  135. struct Library *DiskfontBase;
  136. static char AMIGA_FontName[MAX_ID_LEN+1] = ""; /* name of font */
  137. static int AMIGA_FontSize = 0;                 /* size of font in pts */
  138. static struct TextAttr AMIGA_Font = {
  139.   "topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT
  140. };
  141. static struct TextFont *AMIGA_TextFont;
  142. static struct NewScreen AMIGA_NewScreen = {
  143.   0,0,AMIGA_XMAX,AMIGA_YMAX,4,15,0,HIRES|LACE,
  144.   CUSTOMSCREEN|SCREENBEHIND|SCREENQUIET,NULL,NULL,NULL,NULL
  145. };
  146. static struct Screen *AMIGA_Screen;
  147. static UWORD AMIGA_Colors [] = {
  148.   0x000,0xfff,0xbbb,0x0f0,0xf00,0x00f,0x3ca,0xf0f,
  149.   0x94d,0x0ff,0x82f,0xff0,0x0af,0xc5e,0xfa2,0xf44
  150. };
  151. static int AMIGA_slinetype;
  152. static enum JUSTIFY AMIGA_justify = LEFT;
  153. static unsigned int AMIGA_ymax,AMIGA_xmax; 
  154. static WORD AMIGA_cwd,AMIGA_cht,AMIGA_bsl,AMIGA_vadj;
  155. static struct TagItem AMIGA_ScrTagList[] = {
  156.   {SA_Overscan,OSCAN_TEXT},{TAG_DONE,0}
  157. };
  158.  
  159.  
  160. TERM_PUBLIC void AMIGA_reset()
  161. {
  162.   if (AMIGA_TextFont != NULL) CloseFont(AMIGA_TextFont);
  163.   if (DiskfontBase != NULL) CloseLibrary(DiskfontBase);
  164.   if (AMIGA_Screen != NULL) CloseScreen(AMIGA_Screen);
  165.   if (IntuitionBase != NULL) CloseLibrary((struct Library *)IntuitionBase);
  166.   if (GfxBase != NULL) CloseLibrary((struct Library *)GfxBase);
  167.   AMIGA_TextFont = NULL;
  168.   DiskfontBase = NULL;
  169.   AMIGA_Screen = NULL;
  170.   IntuitionBase = NULL;
  171.   GfxBase = NULL;
  172. }
  173.  
  174.  
  175. TERM_PUBLIC void AMIGA_init()
  176. {
  177.   char name[MAX_ID_LEN+1];
  178.  
  179. #ifdef AMIGA_SC_6_1
  180.   /* Install exit trap in case of abnormal termination (see below). */
  181.   int AMIGA_exit(int);
  182.   if (!onexit((void (*)(void))(&AMIGA_exit))) {
  183.     fprintf(stderr,"Couldn't set exit trap\n");
  184.     exit(20);
  185.   }
  186. #endif
  187.   GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0);
  188.   if (GfxBase == NULL) {
  189.     fprintf(stderr,"No Graphics-Library\n");
  190.     AMIGA_reset();
  191.     exit(20);
  192.   }
  193.   IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0);
  194.   if (IntuitionBase == NULL) {
  195.     fprintf(stderr,"No Intuition-Library\n");
  196.     AMIGA_reset();
  197.     exit(20);
  198.   }
  199.  
  200.   if (IntuitionBase->LibNode.lib_Version <= 34) {
  201.     /* We compute the vertical resolution for those poor NTSC-souls   :-)   */
  202.     if (GfxBase->DisplayFlags & PAL) AMIGA_ymax = 512;
  203.     else AMIGA_ymax = 400;
  204.     AMIGA_xmax = 640;
  205.     AMIGA_NewScreen.Width = AMIGA_xmax;
  206.     AMIGA_NewScreen.Height = AMIGA_ymax;
  207. /* added struct to avoid warning while compiling with gcc */
  208.     AMIGA_Screen = (struct Screen *)OpenScreen(&AMIGA_NewScreen);
  209.     if (AMIGA_Screen == NULL) {
  210.       fprintf(stderr,"No Screen\n");
  211.       AMIGA_reset();
  212.       exit(20);
  213.     }
  214.   } else {
  215.     /* Kickstart 2.0 support */
  216.     AMIGA_NewScreen.Width = STDSCREENWIDTH;
  217.     AMIGA_NewScreen.Height = STDSCREENHEIGHT;
  218. /* added struct to avoid warning while compiling with gcc */
  219.     AMIGA_Screen = (struct Screen *)OpenScreenTagList(&AMIGA_NewScreen,AMIGA_ScrTagList);
  220.     if (AMIGA_Screen == NULL) {
  221.       fprintf(stderr,"No Screen\n");
  222.       AMIGA_reset();
  223.       exit(20);
  224.     }
  225.     AMIGA_xmax = AMIGA_Screen->Width;
  226.     AMIGA_ymax = AMIGA_Screen->Height;
  227.   }
  228.   term->xmax = AMIGA_xmax;
  229.   term->ymax = AMIGA_ymax;
  230.  
  231.   sprintf(name,"%s,%d",AMIGA_FontName,AMIGA_FontSize);
  232.   AMIGA_set_font(name);
  233.  
  234.   LoadRGB4(&AMIGA_Screen->ViewPort,AMIGA_Colors,16);
  235.   RemakeDisplay();
  236.   AMIGA_slinetype = 1;
  237.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  238.   SetDrMd(&AMIGA_Screen->RastPort,JAM1);
  239. }
  240.  
  241.  
  242. TERM_PUBLIC void AMIGA_options()
  243. {
  244.   if (!END_OF_COMMAND && isstring(c_token)) {
  245.     quote_str(AMIGA_FontName,c_token, MAX_ID_LEN);
  246.     c_token++;
  247.   }
  248.  
  249.   if (!END_OF_COMMAND) {
  250.     /* We have font size specified */
  251.     struct value a;
  252.     AMIGA_FontSize = (int)real(const_express(&a));
  253.   }
  254.   
  255.   if (strcmp(AMIGA_FontName,"") == 0 && AMIGA_FontSize != 0)
  256.     strcpy(AMIGA_FontName,"topaz");
  257.   if (strcmp(AMIGA_FontName,"") != 0 && AMIGA_FontSize == 0)
  258.     AMIGA_FontSize = 8;
  259.  
  260.   if (strcmp(AMIGA_FontName,"") != 0 && AMIGA_FontSize != 0) {
  261.     sprintf(default_font,"%s,%d",AMIGA_FontName,AMIGA_FontSize);
  262.     sprintf(term_options,"\"%s\" %d",AMIGA_FontName,AMIGA_FontSize);
  263.   }
  264. }
  265.  
  266.  
  267. TERM_PUBLIC void AMIGA_text()
  268. {
  269.   char c;
  270.   FILE *fp;
  271.  
  272.   if ((fp = fopen("*","r")) != NULL) {
  273.     c = getc(fp);
  274.     ungetc(c,stdin);
  275.   }
  276.   fclose(fp);
  277.   ScreenToBack(AMIGA_Screen);
  278. }
  279.  
  280.  
  281. TERM_PUBLIC void AMIGA_graphics()
  282. {
  283.   SetRast(&AMIGA_Screen->RastPort,0);
  284.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  285.   ScreenToFront(AMIGA_Screen);
  286. }
  287.  
  288.  
  289. TERM_PUBLIC void AMIGA_move(x,y)
  290. unsigned int x,y;
  291. {
  292.   if ((x>=AMIGA_xmax) || (y>=AMIGA_ymax)) return;
  293.   Move(&AMIGA_Screen->RastPort,x,AMIGA_VTF(y));
  294. }
  295.  
  296.  
  297. TERM_PUBLIC void AMIGA_vector(x,y)
  298. unsigned int x,y;
  299. {
  300.   if ((x>=AMIGA_xmax) || (y>=AMIGA_ymax)) return;
  301.   Draw(&AMIGA_Screen->RastPort,x,AMIGA_VTF(y));
  302. }
  303.  
  304.  
  305. TERM_PUBLIC void AMIGA_linetype(linetype)
  306. int linetype;
  307. {
  308.   if (linetype >= 13) linetype %= 13;
  309.   if (linetype < -2) linetype = -2;
  310.   AMIGA_slinetype = linetype+3;
  311.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  312. }
  313.  
  314.  
  315. TERM_PUBLIC void AMIGA_put_text(x,y,str)
  316. unsigned int x,y;
  317. char *str;
  318. {
  319.   LONG len,tx_len;
  320.   WORD xmin,xmax,ymin,ymax;
  321.  
  322.   len = strlen(str);
  323.   tx_len = TextLength(&AMIGA_Screen->RastPort,str,len);
  324.   switch (AMIGA_justify) {
  325.     case LEFT:
  326.       xmin = x;
  327.       xmax = x + tx_len;
  328.       break;
  329.     case CENTRE:
  330.       xmin = x - tx_len / 2;
  331.       xmax = x + tx_len - tx_len / 2; /* aviod roundoff errors ! */
  332.       break;
  333.     case RIGHT:
  334.       xmin = x - tx_len;
  335.       xmax = x;
  336.       break;
  337.   }
  338.   ymin = AMIGA_VTF(y) - AMIGA_vadj;
  339.   ymax = ymin + AMIGA_cht;
  340.   /* Check if character-string lies completely within the screen: */
  341.   if ((xmax >= AMIGA_xmax) || (ymin < 0) || (ymax >= AMIGA_ymax)) return;
  342.   Move(&AMIGA_Screen->RastPort,xmin,ymin+AMIGA_bsl);
  343.   Text(&AMIGA_Screen->RastPort,str,len);
  344. }
  345.  
  346.  
  347. TERM_PUBLIC int AMIGA_justify_text(mode)
  348. enum JUSTIFY mode;
  349. {
  350.   AMIGA_justify = mode;
  351.   return TRUE;
  352. }
  353.  
  354.  
  355. TERM_PUBLIC int AMIGA_set_font(font)
  356. char *font;
  357. {
  358.   static char test_str[] =
  359.     " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
  360.   static WORD test_len,test_pxl;
  361.   char name[MAX_ID_LEN+1];
  362.   int  size,sep;
  363.   
  364.   sep = strcspn(font,",");
  365.   strncpy(name,font,sep);
  366.   name[sep] = '\0';
  367.   size = AMIGA_FontSize;
  368.   sscanf(&(font[sep+1]),"%d",&size);
  369.  
  370.   if (strcmp(name,"") != 0) {
  371.     strncat(name,".font",MAX_ID_LEN+1);
  372.     /* Avoid opening "diskfont.library" if a built-in font is desired */
  373.     if ((strcmp("topaz.font",name) == 0) &&
  374.         ((size == TOPAZ_EIGHTY) || (size == TOPAZ_SIXTY))) {
  375.       AMIGA_Font.ta_Name = name;
  376.       AMIGA_Font.ta_YSize = size;
  377.       AMIGA_Font.ta_Style = FS_NORMAL;
  378.       AMIGA_Font.ta_Flags = FPF_ROMFONT;
  379. /* added struct to avoid warning while compiling with gcc */
  380.       AMIGA_TextFont = (struct TextFont *)OpenFont(&AMIGA_Font);
  381.       if (AMIGA_TextFont != NULL) 
  382.         SetFont(&AMIGA_Screen->RastPort,AMIGA_TextFont);
  383.     } else {
  384.  
  385. /* added struct to avoid warning while compiling with gcc */
  386.  
  387.       DiskfontBase = (struct Library *)OpenLibrary("diskfont.library",0);
  388.       if (DiskfontBase != NULL) {
  389.         AMIGA_Font.ta_Name = name;
  390.         AMIGA_Font.ta_YSize = size;
  391.         AMIGA_Font.ta_Style = FS_NORMAL;
  392.         AMIGA_Font.ta_Flags = FPF_ROMFONT|FPF_DISKFONT;
  393. /* added struct to avoid warning while compiling with gcc */
  394.         AMIGA_TextFont =(struct TextFont *)OpenDiskFont(&AMIGA_Font);
  395.         if (AMIGA_TextFont != NULL)
  396.           SetFont(&AMIGA_Screen->RastPort,AMIGA_TextFont);
  397.       }
  398.     }
  399.   }
  400.  
  401.   /* Width of characters: This works better for proportional fonts than */
  402.   /* AMIGA_Screen->RastPort.TxWidth + AMIGA_Screen->RastPort.TxSpacing */
  403.   test_len = strlen(test_str);
  404.   test_pxl = TextLength(&AMIGA_Screen->RastPort,test_str,test_len);
  405.   AMIGA_cwd = test_pxl / test_len;
  406.   AMIGA_cht = AMIGA_Screen->RastPort.TxHeight; /* Height of characters */
  407.   AMIGA_bsl = AMIGA_Screen->RastPort.TxBaseline; /* Reference line */
  408.   /* Amount by which characters have to be shifted upwards to be */
  409.   /* vertically justified: */
  410.   AMIGA_vadj = AMIGA_bsl / 2;
  411.   term->v_char = AMIGA_cht + 4; /* So lines won't be too close */
  412.   term->h_char = AMIGA_cwd;
  413.  
  414.   return TRUE;
  415. }
  416.  
  417.  
  418. TERM_PUBLIC void AMIGA_suspend()
  419. {
  420.   char c;
  421.   FILE *fp;
  422.  
  423.   if ((fp = fopen("*","r")) != NULL) {
  424.     c = getc(fp);
  425.     ungetc(c,stdin);
  426.   }
  427.   fclose(fp);
  428.   ScreenToBack(AMIGA_Screen);
  429. }
  430.  
  431.  
  432. TERM_PUBLIC void AMIGA_resume()
  433. {
  434.   ScreenToFront(AMIGA_Screen);
  435. }
  436.  
  437.  
  438. /* This function is mainly included if the program terminates abnormally */
  439. /* and the screen and libraries are still open. It closes down all opened */
  440. /* libraries and screens. This happens e.g. when loading "bivariat.demo" */
  441. /* and the stack is smaller than 120000 bytes. */
  442. #ifdef AMIGA_SC_6_1
  443. int AMIGA_exit(rc)
  444. int rc;
  445. {
  446.   AMIGA_reset();
  447.   rawcon(0);
  448.   return rc;
  449. }
  450. #endif
  451.  
  452.  
  453. #endif /* TERM_BODY */
  454.  
  455. #ifdef TERM_TABLE
  456.  
  457. TERM_TABLE_START(amiga_driver)
  458.   "amiga", "Amiga Custom Screen",
  459.   AMIGA_XMAX, AMIGA_YMAX, AMIGA_VCHAR, AMIGA_HCHAR, 
  460.   AMIGA_VTIC, AMIGA_HTIC, AMIGA_options, AMIGA_init, AMIGA_reset, 
  461.   AMIGA_text, null_scale, AMIGA_graphics, AMIGA_move, AMIGA_vector,
  462.   AMIGA_linetype, AMIGA_put_text, null_text_angle, 
  463.   AMIGA_justify_text, do_point, do_arrow, AMIGA_set_font,
  464.   0, /* pointsize */
  465.   TERM_CAN_MULTIPLOT, AMIGA_suspend, AMIGA_resume
  466. TERM_TABLE_END(amiga_driver)
  467.  
  468. #undef LAST_TERM
  469. #define LAST_TERM amiga_driver
  470.  
  471. #endif /* TERM_TABLE */
  472. #endif /* TERM_PROTO_ONLY */
  473.  
  474.  
  475. #ifdef TERM_HELP
  476. START_HELP(amiga)
  477. "1 amiga",
  478. "?set terminal amiga",
  479. "?amiga",
  480. " Two options may be set in the Amiga terminal driver.",
  481. "",
  482. " Syntax:",
  483. "         set terminal amiga {\"<fontname>\"} {<fontsize>}",
  484. "",
  485. " Here, \"<fontname>\" is the name of a valid Amiga system font; <fontsize> ",
  486. " is the size of the font.  The driver uses the font chosen with the",
  487. " Preferences program as the default font if no fontname is given.",
  488. "",
  489. " Examples:",
  490. "",
  491. "         set term amiga",
  492. "         set term amiga \"times\"",
  493. "         set term amiga 11",
  494. "         set term amiga \"CGTriumvirate\" 15"
  495. END_HELP(amiga)
  496. #endif
  497.  
  498. /*
  499.  * NAME: amiga
  500.  *
  501.  * OPTIONS: fontname (default topaz) fontsize (default 8)
  502.  *
  503.  * SUPPORTS: Commodore Amiga Computers
  504.  *
  505.  * Further Info: Supports Kickstart 2.0 and even compiles with Aztec C
  506.  *         Version 5.2beta (I have no idea what I'm talking
  507.  *         about). Uses a virtual screen, plot size might be
  508.  *         larger than that of the screen.
  509.  *
  510.  * NOTE: There has been a new version (for Amiga 3.0 whatever that
  511.  *     means) in c.g.a.g in old style terminal format. I sent a mail
  512.  *     to the author and asked him to contact Carsten Steger (the 
  513.  *     author of this file). Don't know if that ever happened.
  514.  *
  515.  */
  516.  
  517.